package com.cms.config;

import com.cms.controller.HelloController;
import com.cms.controller.HomeController;
import com.cms.controller.ServerConfig.ServerConfigController;
import com.cms.controller.TableController;
import com.cms.controller.configuration.ConfigurationController;
import com.cms.controller.operation.InterfaceController;
import com.cms.interceptor.CmsActionInterceptor;
import com.jfinal.config.*;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;






import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 */
public class CmsConfig extends JFinalConfig {


    private static final Logger logger = LoggerFactory.getLogger(CmsConfig.class);

    @Override
    public void configConstant(Constants constance) {
        constance.setDevMode(true);
        constance.setViewType(ViewType.JSP);
        PropKit.use("jdbc.properties");
    }

    @Override
    public void configEngine(Engine arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void configHandler(Handlers arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void configPlugin(Plugins plugins) {
        // TODO Auto-generated method stub

        DruidPlugin dp = new DruidPlugin(PropKit.get("url"), PropKit.get("username"),
                PropKit.get("password"), PropKit.get("driverClassName"));
        dp.setMinIdle(4);
        dp.setInitialSize(1);
        dp.setMaxWait(2000L);
        dp.setMaxActive(8);
        plugins.add(dp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        plugins.add(arp);
        logger.info("[druid] data connection pool initial successfully!");
    }

    @Override
    public void configRoute(Routes routes) {

    	routes.add("/sayHello", HelloController.class);
    	routes.add("/", HomeController.class);
    	routes.add("/table",TableController.class);
    	//接口管理
        routes.add("/interface", InterfaceController.class);
        routes.add("/configuration", ConfigurationController.class);
        routes.add("/serverConfig", ServerConfigController.class);
    }

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		me.addGlobalActionInterceptor(new CmsActionInterceptor());
	}
}
